package org.genntii.warehousesystem.controller;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.genntii.warehousesystem.common.Result;
import org.genntii.warehousesystem.domain.entity.Goods;
import org.genntii.warehousesystem.domain.entity.Type;
import org.genntii.warehousesystem.service.GoodsTypeService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "货品类型关联接口")
@RestController
@RequestMapping("/goodsType")
public class GoodsTypeController {

    @Resource
    private GoodsTypeService goodsTypeService;

    @Operation(summary = "货品添加类别",description = "为货品添加货品类别")
    @Parameter(name = "goodsId",description = "货品",required = true,in = ParameterIn.QUERY)
    @PostMapping("/v1/add")
    public Result addTYpeForGoods(@RequestParam("goodsId")int goodsId, @RequestBody List<Integer> typeList){
        goodsTypeService.typeAdds(typeList,goodsId);
        return Result.success();
    }

    @Operation(summary = "货品删除类别",description = "为货品删除一个类别")
    @Parameters({
            @Parameter(name = "typeId",description = "类型id",required = true,in = ParameterIn.QUERY),
            @Parameter(name = "goodsId",description = "货品id",required = true,in = ParameterIn.QUERY)
    })
    @DeleteMapping("/v1/del")
    public Result del(@RequestParam("typeId")int typeId,@RequestParam("goodsId")int goodsId){
        goodsTypeService.del(typeId,goodsId);
        return Result.success();
    }

    @Operation(summary = "获取货品类别列表",description = "通过货品查找其货品类别")
    @Parameter(name = "goodsId",description = "货品id",required = true,in = ParameterIn.QUERY)
    @GetMapping("/getTypesByGoods")
    public Result<List<Type>> getTypesByGoods(@RequestParam("goodsId")int goodsId){
        return Result.success(goodsTypeService.showAllTypeByGoodsId(goodsId));
    }
    @Operation(summary = "通过类别分页查找货品")
    @Parameters({
            @Parameter(name = "typeId",description = "类别id",required = true,in = ParameterIn.QUERY),
            @Parameter(name = "page",description = "页码",required = true,in = ParameterIn.QUERY)
    })
    @GetMapping("/findGoodsByType")
    public Result<List<Goods>> findGoodsByType(@RequestParam("typeId")int typeId, @RequestParam("page")int page){
        return Result.success(goodsTypeService.selectGoodsByTypeId(typeId, page));
    }

}
